# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: helpers\mailer\renderer\jinja.py
import logging
from jinja2 import Environment, FileSystemLoader
from helpers.mailer.renderer.base import Renderer
from helpers.mailer.renderer.filters import flt_datetime

logger = logging.getLogger("mailer.renderer.jinja")


class JinjaRenderer(Renderer):
    def __init__(self, templates_path, **extra_args):
        super().__init__()
        self.jinja_environment = Environment(
            autoescape=False,
            extensions=["jinja2.ext.autoescape"],
            loader=FileSystemLoader(templates_path),
            **extra_args
        )
        self.jinja_environment.filters["flt_datetime"] = flt_datetime

    def render(self, data, template_name):
        result = None
        try:
            template = self.jinja_environment.get_template(template_name)
            if template:
                result = template.render(data)
            else:
                logger.warning("template not found [%s]", template_name)
        except Exception as e:
            logger.warning("render template %s raised %s", template_name, e)

        return result
